package Client.View;

import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JFrame;
import javax.swing.JPanel;

import Client.Model.GameModel;


/**
 * @author Rodrigo
 *
 */


@SuppressWarnings("serial")
public class GameFrame extends JFrame implements Observer{

	private Container cp;
    private GameModel model;
    private int height;
    private int width;
    
	public GameFrame(GameModel m, int height, int width) {
				
		  	super("NavalBattle"); 
	        
	        this.model = m;
	        this.height = height;
	        this.width = width;
	        
	           
	        cp = getContentPane();
	        model.addObserver(this);
	           
	        
	        setLocation(300, 100); 
	        setPreferredSize(new Dimension(width, height));
	        
	        setResizable(false);
	        
	        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//Terminate Application        
	        setVisible(true); 

	        setView();
	        
	        this.pack();
	        validate();
	        repaint();

	}


	@Override
	public void update(Observable o, Object arg) {

		if (model.getView()==GameModel.VIEW_INITIAL){
			this.setVisible(false);
		}
		else{
			this.setVisible(true);
			this.revalidate();
			this.repaint();
		}
		
	}
	
	private void setView(){
		
		this.setBackground(new Color(17, 178, 233));
		cp.setBackground(new Color(17, 178, 233));
		cp.setLayout(null);
		
		JPanel panel;

		panel = new GameView(this.model, height, width);
		panel.setVisible(false);
		cp.add(panel);
		
		panel = new ConnectedView(this.model, height, width);
		panel.setVisible(false);
		cp.add(panel);
		
		
		
	}
	
	
}
